# 导包
import requests


# 创建封装模块的类
class LoginApi:

    # 登录接口实现封装
    def login(self, json_dict):
        url = 'http://ihrm-test.itheima.net/api/sys/login'
        return requests.post(url=url, json=json_dict)

    # 获取完整的token
    def get_token(self, json_dict):
        # return "Bearer" + " " + self.login(json_dict).json().get("data")
        res = self.login(json_dict)
        res_json = res.json()
        token_value = res_json.get("data")
        token = "Bearer" + " " + token_value
        return token


# if __name__ == '__main__':
#     # 1.实例化封装登录的类
#     login_api = LoginApi()
#     # 2.调用封装登录方法,获取响应结果
#     # 定义字典变量,用来接收请求体数据
#     json_dict = {"mobile": "13800000002", "password": "123456"}
#     res = login_api.login(json_dict)
#     # 3.调用response对象,将响应数据解析为json
#     print(res.json())
if __name__ == '__main__':
    # 1.实例化封装
    login_api = LoginApi()
    # 调用获取token的方法,获取完整的token
    json_dict = {"mobile": "13800000002", "password": "123456"}
    print(login_api.get_token(json_dict))
